---
category: Array
created: '2021-04-20'
title: Find the index of the maximum item of an array
updated: '2021-10-13'
---

**JavaScript version**

```js indexOfMax.js
const indexOfMax = (arr) => arr.reduce((prev, curr, i, a) => (curr > a[prev] ? i : prev), 0);
```

**TypeScript version**

```ts indexOfMax.ts
const indexOfMax = (arr: number[]): number => arr.reduce((prev, curr, i, a) => (curr > a[prev] ? i : prev), 0);
```

**Examples**

```js examples.js
indexOfMax([1, 3, 9, 7, 5]); // 2
indexOfMax([1, 3, 7, 7, 5]); // 2
```
